class Site::DesignController < ApplicationController
  before_filter :protect, :only => [:show]
  def index
    @title = "创意设计"
    @newests = Retype.find_newest_designs
    @products = Retype.find_less_designs(100000)
    @brands = Retype.find_less_designs(110000)
    @others = Retype.find_less_designs(190000)
    render :layout => false
  end

  def detail
    id = params[:id]
    @retype = Retype.find_by_level(id)
    @title = "#{@retype.name}创意"
    @newests = @retype.find_newest_designs
    @designs = @retype.works.paginate(:page => params[:page], :per_page => PERPAGE, :order => "updated_at DESC")
  end
  
  def show
    @design = Work.find(params[:id])
    @title = @design.title
    
    if param_posted?(:workComment) && !params[:workComment][:content].blank?
      content = params[:workComment][:content]
      content = content.gsub(/\[emot\]/,"<img src='/images/emotions/")
      content = content.gsub(/\[\/emot\]/,".gif'>")
      params[:workComment][:content] = content
      @comment = WorkComment.new(params[:workComment])
      @comment.user = @login_user
      @comment.work = @design
      if (@design.work_comments << @comment)
        @comment=nil
      end
    end
    render :layout => false
  end
  
  

end
